package com.yanqu.collectclientdata.timer;

import com.yanqu.road.utils.executor.ExecutorHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Author wpj
 * @Date 2020/11/28
 */
public class CollectClientDataTimer {
    private static final Logger logger = LogManager.getLogger(CollectClientDataTimer.class.getName());

    private static ScheduledExecutorService timerExecutorService;

    private static SaveDataTimer saveDataTimer;

    public static void init() {
        timerExecutorService = ExecutorHelper.createGameScheduledThreadPoolExecutor(3, "timer-web");
    }

    public static void startTask() {
        saveDataTimer = new SaveDataTimer();
        timerExecutorService.scheduleWithFixedDelay(saveDataTimer, 0, 1, TimeUnit.SECONDS);
    }

    public static void stopTask() {
        saveDataTimer.cancel(true);
    }

}
